﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Ordinaire.Data;

namespace Ordinaire.Social.Data
{
    /// <summary>
    /// Class representation of association table 'OrganisationAddresses'.
    /// </summary>
    [Table]
    public class OrganisationAddresses : JunctionData<Organisations, Addresses, int, string>
    {
        #region Property methods

        /// <summary>
        /// Get or set the entry unique identifier.
        /// </summary>
        [Column(IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
        public override int Id
        {
            get { return base.Id; }
            set { base.Id = value; }
        }

        /// <summary>
        /// Gets or sets the id of the related data in 'Organisations' table.
        /// </summary>
        [Column(Name = "OrganisationId", DbType = "int NOT NULL", UpdateCheck = UpdateCheck.Never)]
        public override int IdA
        {
            get { return base.IdA; }
            set { base.IdA = value; }
        }

        /// <summary>
        /// Gets or sets the name of the organisation address: Head Office, Manufacturing, etc.
        /// </summary>
        [Column(DbType = "nvarchar(20)", UpdateCheck = UpdateCheck.Never)]
        public override string Name
        {
            get { return base.Name; }
            set { base.Name = value; }
        }

        /// <summary>
        /// Gets or sets the id of the related data in 'Addresses' table.
        /// </summary>
        [Column(Name = "AddressId", DbType = "int NOT NULL", UpdateCheck = UpdateCheck.Never)]
        public override int IdB
        {
            get { return base.IdB; }
            set { base.IdB = value; }
        }

        /// <summary>
        /// Get or set the username who created this entry.
        /// </summary>
        [Column(DbType = "nvarchar(10) NOT NULL", UpdateCheck = UpdateCheck.Never)]
        public override string CreatedBy
        {
            get { return base.CreatedBy; }
            set { base.CreatedBy = value; }
        }

        /// <summary>
        /// Get or set the date when the entry was first created.
        /// </summary>
        [Column(DbType = "datetime", UpdateCheck = UpdateCheck.Never)]
        public override DateTime? CreateDate
        {
            get { return base.CreateDate; }
            set { base.CreateDate = value; }
        }

        #endregion

        #region Association

        /// <summary>
        /// Gets or sets the associated data from table 'Organisations'.
        /// </summary>
        [Association(Name = "FK_OrganisationsAddresses_Organisations", IsForeignKey = true, ThisKey = "IdA", Storage = "dataA")]
        public override Organisations DataA
        {
            get { return base.DataA; }
            set { base.DataA = value; }
        }

        [Association(Name = "FK_OrganisationsAddresses_Addresses", IsForeignKey = true, ThisKey = "IdB", Storage = "dataB")]
        public override Addresses DataB
        {
            get { return base.DataB; }
            set { base.DataB = value; }
        }

        #endregion

        #region Expression

        /// <summary>
        /// Returns a related expression to find data that matches with the specified organisation and addresses ids.
        /// </summary>
        /// <param name="organisationId">the id of Organisations data to search for</param>
        /// <param name="addressId">the id of Addresses data to search for</param>
        /// <returns>related expression</returns>
        public static Expression<Func<OrganisationAddresses, bool>> Are(int organisationId, int addressId)
        {
            return d => d.IdA.Equals(organisationId) && d.IdB.Equals(addressId);
        }

        #endregion
    }
}
